/**
 * Created by CodeTlan.
 * User: Ing. Miguel Salas
 * Date: 3/6/12
 * Time: 3:40 AM
 */
Ext.define('CT.controller.Loggeds', {
    extend:'Ext.app.Controller',
    stores:[
        'MenuImages'
    ],
    models:[
        'MenuImage'
    ],
    init:function () {
        this.control({
            'menuprincipal':{
                itemclick:this.onClickItem,
                afterrender:function(view){
                    view.store.on('load',function(){
                        view.store.add({"titulo":"Salir","img_big":"img\/modulos\/icons\/64\/salir.png","menu_mostrar":"1"});
                    },this);
                }
            }

        });
    },

    onClickItem:function (view, record, index, e, o) {
        var itemId = record.data.modulo_k;
        if (record.data.titulo == "Salir") {
            Ext.Ajax.request({
                url:'index.php/users/logout',
                method:'post',
                success:function (response) {
                    location.href = "index.php";
                }
            });
        } else {
            Ext.require('CT.controller.'+record.data.controller,function(){
                var controller=this.getController(record.data.controller);
                controller.lanzarVentana("menu-"+itemId,record.data.icon_cls);
            },this);

        }

    }
});